﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLNGP.Common.Extensions
{
    public static class LinqExtensions
    {
        public static IEnumerable<T> SelectHierarchy<T>(this T obj, Func<T, IEnumerable<T>> hierarchySelector)
        {
            yield return obj;
            var children = hierarchySelector(obj);
            if (children != null)
            {
                foreach (T t in children)
                {
                    foreach (var tChild in SelectHierarchy(t, hierarchySelector))
                    {
                        yield return tChild;
                    }
                }
            }
        }
    }
}
